package com.prawn.ift.ctrlequipment.dao;

import com.prawn.ift.ctrlequipment.pojo.Ctrlequipment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * 数据访问接口
 *
 * @author Administrator
 */
public interface CtrlequipmentDao extends JpaRepository<Ctrlequipment, String>, JpaSpecificationExecutor<Ctrlequipment> {

    @Modifying
    @Transactional
    @Query("update Ctrlequipment a set " +
            "a.updateDate= CASE WHEN :#{#ctrlequipment.updateDate} IS NULL THEN a.updateDate ELSE :#{#ctrlequipment.updateDate} END ," +
            "a.isService= CASE WHEN :#{#ctrlequipment.isService} IS NULL THEN a.isService ELSE :#{#ctrlequipment.isService} END ," +
            "a.number= CASE WHEN :#{#ctrlequipment.number} IS NULL THEN a.number ELSE :#{#ctrlequipment.number} END ," +
            "a.name= CASE WHEN :#{#ctrlequipment.name} IS NULL THEN a.name ELSE :#{#ctrlequipment.name} END ," +
            "a.ctrlChannelId= CASE WHEN :#{#ctrlequipment.ctrlChannelId} IS NULL THEN a.ctrlChannelId ELSE :#{#ctrlequipment.ctrlChannelId} END ," +
            "a.ctrlChannelNo= CASE WHEN :#{#ctrlequipment.ctrlChannelNo} IS NULL THEN a.isService ELSE :#{#ctrlequipment.ctrlChannelNo} END ," +
            "a.ctrlChannelName= CASE WHEN :#{#ctrlequipment.ctrlChannelName} IS NULL THEN a.ctrlChannelName ELSE :#{#ctrlequipment.ctrlChannelName} END ," +
            "a.serial= CASE WHEN :#{#ctrlequipment.serial} IS NULL THEN a.serial ELSE :#{#ctrlequipment.serial} END ," +
            "a.typeId= CASE WHEN :#{#ctrlequipment.typeId} IS NULL THEN a.typeId ELSE :#{#ctrlequipment.typeId} END ," +
            "a.equipmentId= CASE WHEN :#{#ctrlequipment.equipmentId} IS NULL THEN a.equipmentId ELSE :#{#ctrlequipment.equipmentId} END ," +
            "a.equipmentName= CASE WHEN :#{#ctrlequipment.equipmentName} IS NULL THEN a.equipmentName ELSE :#{#ctrlequipment.equipmentName} END ," +
            "a.sceneId= CASE WHEN :#{#ctrlequipment.sceneId} IS NULL THEN a.sceneId ELSE :#{#ctrlequipment.sceneId} END ," +
            "a.model= CASE WHEN :#{#ctrlequipment.model} IS NULL THEN a.model ELSE :#{#ctrlequipment.model} END ," +
            "a.purchaseTime= CASE WHEN :#{#ctrlequipment.purchaseTime} IS NULL THEN a.purchaseTime ELSE :#{#ctrlequipment.purchaseTime} END ," +
            "a.effectTime= CASE WHEN :#{#ctrlequipment.effectTime} IS NULL THEN a.effectTime ELSE :#{#ctrlequipment.effectTime} END ," +
            "a.expirationTime= CASE WHEN :#{#ctrlequipment.expirationTime} IS NULL THEN a.expirationTime ELSE :#{#ctrlequipment.expirationTime} END ," +
            "a.remarks= CASE WHEN :#{#ctrlequipment.remarks} IS NULL THEN a.remarks ELSE :#{#ctrlequipment.remarks} END ," +
            "a.createBy= CASE WHEN :#{#ctrlequipment.createBy} IS NULL THEN a.createBy ELSE :#{#ctrlequipment.createBy} END ," +
            "a.createDate= CASE WHEN :#{#ctrlequipment.createDate} IS NULL THEN a.purchaseTime ELSE :#{#ctrlequipment.createDate} END ," +
            "a.updateBy= CASE WHEN :#{#ctrlequipment.updateBy} IS NULL THEN a.updateBy ELSE :#{#ctrlequipment.updateBy} END ," +
            "a.delFlag= CASE WHEN :#{#ctrlequipment.delFlag} IS NULL THEN a.delFlag ELSE :#{#ctrlequipment.delFlag} END " +
            "where a.id = :#{#ctrlequipment.id}")
    int updateSelective(@Param("ctrlequipment") Ctrlequipment ctrlequipment);

}
